package main

import (
	"emsctrl/apicmd"
	"emsctrl/ctrlMode"
	"emsctrl/db"
	"emsctrl/mqttclient"
	"emsctrl/rpcClient"
	"emsctrl/servicedevmap"
	"time"
)

func main() {

	init := ctrlMode.PolicyInit()
	rpcInit := rpcClient.RpcInit()

	db.InitDb()
	mqttInit := mqttclient.MqttInit(rpcInit.Mqtt.Host, rpcInit.Mqtt.Port)
	defer func() {
		rpcClient.RpcStop()
		mqttInit.Disconnect(0)
		db.ExitDb()
	}()
	servicedevmap.Run()
	apicmd.ApiInit(init)
	go init.Run()
	for {
		time.Sleep(time.Second)
	}
}
